package com.hhd.flow.controller;

import com.hhd.flow.vo.PreStartProcessVo;
import com.hhd.flow.vo.Result;
import com.hhd.flow.engine.FlowEngine;
import com.hhd.flow.engine.cmd.CommandResult;
import com.hhd.flow.engine.cmd.impl.virtual.VirtualStartCommand;
import com.hhd.flow.engine.vo.UserManualSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/flow")
public class PreStartProcessController {
    @Autowired
    FlowEngine flowEngine;

    @RequestMapping("/preStartProcess")
    @Transactional
    public Result preStartProcess(@RequestBody PreStartProcessVo preStartProcessVo) {
        VirtualStartCommand command = flowEngine.newVirtualStartCommandBuilder()
                .formModel(preStartProcessVo.getFormModel())
                .formTypeId(preStartProcessVo.getFormTypeId())
                .processDefinitionId(preStartProcessVo.getProcessDefinitionId())
                .formId(preStartProcessVo.getFormId()).build();
        CommandResult<UserManualSelect> result = flowEngine.execute(command);
        return Result.ok(result.getResult());
    }
}
